﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class 我借到的图书和归还 : Form
    {
        public 我借到的图书和归还()
        {
            InitializeComponent();
        }

        public void table()
        {
            dataGridView1.Rows.Clear();
            Dao dao = new Dao();
            string sql = $"select [no],[bid],[datetime] from t_lend where [uid] = '{Data.UID}'";
            IDataReader dc = dao.read(sql);
            while (dc.Read())
            {
                dataGridView1.Rows.Add(dc[0].ToString(), dc[1].ToString(), dc[2].ToString());

            }
            dc.Close();
            dao.Daoclose();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            string no = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            string id = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            string sql = $"delete from t_lend where [no]='{no}';update t_book set number = number +1 where id ='{id}'";
            Dao dao = new Dao();
            if (dao.Execute(sql)>1)
            {
                MessageBox.Show("归还成功");
                table();
            }
        }

        private void 我借到的图书和归还_Load(object sender, EventArgs e)
        {
            table();
        }
    }
}
